package commands;

import nanoxml.XMLElement;
import utils.ITransmittable;

/**
 * This command represents a request sent from a table client to the table
 * owner to pass to another table client
 */
public class CommandMessageToUser implements ITransmittable
{
	private final static String ATTR_USER_NAME_TO = "UsernameTo";
	private final static String ATTR_MESSAGE = "Message";
		
	private String usernameTo = null;
	private String message = null;

	
	public CommandMessageToUser (String usernameTo, String message)
	{
		this.usernameTo = usernameTo;
		this.message = message;
	}

	public CommandMessageToUser (XMLElement message)
	{
		this.usernameTo = (String) message.getAttribute(ATTR_USER_NAME_TO);
		this.message = (String) message.getAttribute(ATTR_MESSAGE);
	}

	
	@Override
	public XMLElement toXML()
	{
		XMLElement xmlMessage = new XMLElement();
		
		xmlMessage.setName(Commands.MESSAGE_TO_USER);
		xmlMessage.setAttribute(ATTR_USER_NAME_TO, usernameTo);
		xmlMessage.setAttribute(ATTR_MESSAGE, message);
		
		return xmlMessage;
	}

	public String getUsernameTo()
	{
		return usernameTo;
	}
	
	public String getMessage()
	{
		return message;
	}
}
